use Validation;

package ValidateActingEntity;

@ISA = qw/Operation/;


sub init{
    my $self = shift;

    $self->dependencies(qw/LogManager EntityManager/);
}

## Attempt to find an entity in the parameters
## This entity is the one performing the action
## If it cannot find an entity ref under the key ENTITY
## , attempts to retrieve a WELL_KNOWN_ENTITY by name from
## the entity manager
sub perform{
    my $self = shift;
    my ($entity, $wellKnownEntity) = ($self->params->{ENTITY},
				      $self->params->{WELL_KNOWN_ENTITY});
    my $lm = $self->{LogManager};

    if(! (defined $entity)){
	if(! (defined $wellKnownEntity)){
	    $lm->log(ref($self).": ERROR - No entity defined" );
	    return ActionResult->new("FAILURE", "ERROR");
	}else{
	    my $entity = $self->{EntityManager}->entities->category($wellKnownEntity)->[0];
	    if(! defined $entity){
		$lm->log(ref($self).": ERROR - Well known entity ".$wellKnownEntity." not found" );
		return ActionResult->new("FAILURE", "ERROR");

	    } # if well known entity did not exist
	    else {
		$self->params->{ENTITY} = $entity;
	    } # if well known entity existed
	} # if no entity was specified, specific or by well known name
    } # if no specific entity was given
#    $lm->log(ref($self).": OK - Entity found");
    return ActionResult->new("SUCCESS", "OK");
} # validateEntity


1;
